import path from "path";
import release from "./tools/sftp";
export default function releasePlugin(params: {
	serverPath: string;
	exclude: string[];
	serverConfig: {
		host: string;
		port: string; // SFTP 默认端口
		username: string;
		password: string;
	};
}) {
	let outDir = "";
	let rootDir = "";
	return {
		name: "close-bundle-plugin",
		configResolved(config: any) {
			// 访问 Vite 配置并保存打包目录
			outDir = config.build.outDir;
			rootDir = config.root;
		},
		closeBundle() {
			release({ ...params, localPath: path.resolve(rootDir, outDir) }).then(
				() => {
					console.log("release success");
				}
			);
		},
	};
}
